import {Suspense} from "react"
import ClassroomDashboard from "@/components/classroom-dashboard"
import { LoadingDashboard } from "@/components/loading-dashboard"
import { ClassSelector } from "@/components/class-selector"
import { VideoMonitoring } from "@/components/flv-play"
// import {cookies} from "next/headers"; // 引入新的客户端组件
import { redirect } from "next/navigation";
import {AuthCheck} from "@/components/AuthCheck";

export default async function Home() {
    // 使用 await 获取 cookies
    // const cookieStore = await cookies();
    // let token = cookieStore.get("token")?.value;
    // if (!token) {
    //     redirect("/login"); // 如果没有登录，跳转到登录页
    // }
    // const videoUrl = "http://localhost:8080/hls/test.m3u8"; // 替换为实际的视频 URL
    // const videoUrl = "rtmp://localhost/live/test"; // 替换为实际的视频 URL
    const videoUrl = "http://localhost:8866/live?url=rtmp://localhost/live/test"; // 替换为实际的视频 URL
    // const videoUrl = "ws://localhost:8866/live?url=rtmp://localhost/live/test"; // 替换为实际的视频 URL
  return (
    <div className="mx-auto max-w-7xl space-y-6">
        <AuthCheck>
          <div className="flex flex-col justify-between gap-4 sm:flex-row sm:items-center">
            <h1 className="text-2xl font-bold md:text-3xl">课堂实时监测</h1>
            <ClassSelector />
          </div>

          {/* 添加视频监测组件 */}
          <VideoMonitoring />
            {/* 添加视频播放组件 */}
            {/*<VideoPlayer url={videoUrl} />*/}

          <Suspense fallback={<LoadingDashboard />}>
            <ClassroomDashboard />
          </Suspense>
        </AuthCheck>
    </div>
  )
}
